{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Valid Clock Times"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string #enumeration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串 #枚举"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countTime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #有效时间的数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个长度为&nbsp;<code>5</code>&nbsp;的字符串&nbsp;<code>time</code>&nbsp;，表示一个电子时钟当前的时间，格式为&nbsp;<code>\"hh:mm\"</code>&nbsp;。<strong>最早</strong>&nbsp;可能的时间是&nbsp;<code>\"00:00\"</code>&nbsp;，<strong>最晚</strong>&nbsp;可能的时间是&nbsp;<code>\"23:59\"</code>&nbsp;。</p>\n",
    "\n",
    "<p>在字符串&nbsp;<code>time</code>&nbsp;中，被字符&nbsp;<code>?</code>&nbsp;替换掉的数位是 <strong>未知的</strong>&nbsp;，被替换的数字可能是&nbsp;<code>0</code>&nbsp;到&nbsp;<code>9</code>&nbsp;中的任何一个。</p>\n",
    "\n",
    "<p>请你返回一个整数<em>&nbsp;</em><code>answer</code>&nbsp;，将每一个 <code>?</code>&nbsp;都用<em>&nbsp;</em><code>0</code>&nbsp;到<em>&nbsp;</em><code>9</code>&nbsp;中一个数字替换后，可以得到的有效时间的数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>time = \"?5:00\"\n",
    "<b>输出：</b>2\n",
    "<b>解释：</b>我们可以将 ? 替换成 0 或 1 ，得到 \"05:00\" 或者 \"15:00\" 。注意我们不能替换成 2 ，因为时间 \"25:00\" 是无效时间。所以我们有两个选择。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>time = \"0?:0?\"\n",
    "<b>输出：</b>100\n",
    "<b>解释：</b>两个 ? 都可以被 0 到 9 之间的任意数字替换，所以我们总共有 100 种选择。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>time = \"??:??\"\n",
    "<b>输出：</b>1440\n",
    "<b>解释：</b>小时总共有 24 种选择，分钟总共有 60 种选择。所以总共有 24 * 60 = 1440 种选择。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>time</code>&nbsp;是一个长度为 <code>5</code>&nbsp;的有效字符串，格式为&nbsp;<code>\"hh:mm\"</code>&nbsp;。</li>\n",
    "\t<li><code>\"00\" &lt;= hh &lt;= \"23\"</code></li>\n",
    "\t<li><code>\"00\" &lt;= mm &lt;= \"59\"</code></li>\n",
    "\t<li>字符串中有的数位是&nbsp;<code>'?'</code>&nbsp;，需要用&nbsp;<code>0</code>&nbsp;到&nbsp;<code>9</code>&nbsp;之间的数字替换。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-valid-clock-times](https://leetcode.cn/problems/number-of-valid-clock-times/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-valid-clock-times](https://leetcode.cn/problems/number-of-valid-clock-times/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"?5:00\"', '\"0?:0?\"', '\"??:??\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        a=1\n",
    "        b=1\n",
    "        if time[0]=='?' and time[1]=='?':\n",
    "            a=24\n",
    "        elif time[0]=='?' and int(time[1])<=3:\n",
    "            a=3\n",
    "        elif time[0]=='?' and int(time[1])>3:\n",
    "            a=2\n",
    "        elif time[1]=='?' and time[0]=='2':\n",
    "            a=4\n",
    "        elif time[1]=='?' and time[0]!='2':\n",
    "            a=10\n",
    "        if time[3]=='?' and time[4]=='?':\n",
    "            b=60\n",
    "        elif time[3]=='?':\n",
    "            b=6\n",
    "        elif time[4]=='?':\n",
    "            b=10\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def countTime(self, time):\n",
    "        \"\"\"\n",
    "        :type time: str\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        count = 1\n",
    "        if time[0:2] == \"??\":\n",
    "            count = 24\n",
    "        elif time[0] == \"?\":\n",
    "            if time[1] > \"3\":\n",
    "                count = 2\n",
    "            else:\n",
    "                count = 3\n",
    "        elif time[1] == \"?\":\n",
    "            if time[0] == \"2\":\n",
    "                count = 4\n",
    "            else:\n",
    "                count = 10\n",
    "        \n",
    "\n",
    "        if time[3:5] == \"??\":\n",
    "            count *= 60\n",
    "        elif time[3] == \"?\":\n",
    "            count *= 6\n",
    "        elif time[4] == \"?\":\n",
    "            count *= 10\n",
    "\n",
    "        \n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hours = 1\n",
    "        if time[0] == \"?\":\n",
    "            if time[1] == \"?\":\n",
    "                hours = 24\n",
    "            else:\n",
    "                hours = 2 if int(time[1]) > 3 else 3\n",
    "        if time[1] == \"?\":\n",
    "            if time[0] == \"?\":\n",
    "                hours = 24\n",
    "            else:\n",
    "                hours = 10 if int(time[0]) < 2 else 4\n",
    "        c = 6 if time[3] == \"?\" else 1\n",
    "        d = 10 if time[4] == \"?\" else 1\n",
    "        print(hours, c, d)\n",
    "        return hours * c * d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 0\n",
    "        for h1 in range(0, 3):\n",
    "            for h2 in range(0, 10):\n",
    "                hour = h1 * 10 + h2\n",
    "                if hour >= 24:\n",
    "                    break\n",
    "                for m1 in range(0, 6):\n",
    "                    for m2 in range(0, 10):\n",
    "                        minute = m1 * 10 + m2\n",
    "                        if minute >= 60:\n",
    "                            break\n",
    "                        if time[0] == '?' or int(time[0]) == h1:\n",
    "                            if time[1] == '?' or int(time[1]) == h2:\n",
    "                                if time[3] == '?' or int(time[3]) == m1:\n",
    "                                    if time[4] == '?' or int(time[4]) == m2:\n",
    "                                        ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hour = 0 \n",
    "        minute = 0\n",
    "        if time[0] == '?' and time[1] == '?':\n",
    "            hour = 24\n",
    "        elif time[0] == '?':\n",
    "            if int(time[1]) <= 3:\n",
    "                hour = 3\n",
    "            else:\n",
    "                hour = 2\n",
    "        elif time[1] == '?':\n",
    "            if int(time[0]) < 2:\n",
    "                hour = 10\n",
    "            else:\n",
    "                hour = 4\n",
    "        if time[3] == '?' and time[4] == '?':\n",
    "            minute = 60\n",
    "        elif time[3] == '?':\n",
    "            minute = 6\n",
    "        elif time[4] == '?':\n",
    "            minute = 10\n",
    "        \n",
    "        if hour == 0 and minute ==0: return 1\n",
    "        elif hour ==0: return minute\n",
    "        elif minute == 0: return hour\n",
    "\n",
    "        return hour * minute\n",
    "        \n",
    "\n",
    "\n",
    "            \n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h = m = 1\n",
    "        \n",
    "        if time[0] == time[1] == '?':\n",
    "            h = 24\n",
    "        elif time[0] == '?':\n",
    "            h = 2 + (time[1] < '4')\n",
    "        elif time[1] == '?':\n",
    "            h = 4 if time[0] == '2' else 10\n",
    "        \n",
    "        if time[3] == '?':\n",
    "            m *= 6\n",
    "        if time[4] == '?':\n",
    "            m *= 10\n",
    "\n",
    "        return h * m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ret = 0\n",
    "        for i in range(24):\n",
    "            for j in range(60):\n",
    "                if i < 10:\n",
    "                    h = '0' + str(i)\n",
    "                else:\n",
    "                    h = str(i)\n",
    "                if j < 10:\n",
    "                    m = '0' + str(j)\n",
    "                else:\n",
    "                    m = str(j)\n",
    "                x = h + ':' + m\n",
    "                for k in range(5):\n",
    "                    if time[k] != '?' and time[k] != x[k]:\n",
    "                        break\n",
    "                else:\n",
    "                    # print(x)\n",
    "                    ret += 1\n",
    "        return ret\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        lst = list(time)\n",
    "        res = 1\n",
    "        ans = 0\n",
    "        if lst[0] == '?':\n",
    "            if lst[1] == '?':\n",
    "                res *= 24\n",
    "            elif int(lst[1]) < 4:\n",
    "                res *= 3\n",
    "            elif int(lst[1]) > 4:\n",
    "                res *= 2\n",
    "            else:\n",
    "                res *= 2\n",
    "        elif lst[1] == '?':\n",
    "            if lst[0] == '0' or lst[0] == '1':\n",
    "                res *= 10\n",
    "            elif lst[0] == '2':\n",
    "                res *= 4\n",
    "        if lst[3] == '?':\n",
    "            if lst[4] == '?':\n",
    "                res *= 60\n",
    "            elif int(lst[4]) >= 0:\n",
    "                res *= 6\n",
    "        elif lst[4] == '?':\n",
    "            if lst[3] == '6':\n",
    "                res *= 1\n",
    "            else:\n",
    "                res *= 10\n",
    "        return ans + res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        res2= 0 \n",
    "        res1 = 0\n",
    " \n",
    "        if time[4]=='?' and time[3]=='?':\n",
    "            res2 = 60\n",
    "        elif time[4]=='?':\n",
    "            res2 = 10\n",
    "        elif time[3]=='?':\n",
    "            res2 = 6\n",
    "        else:\n",
    "            res2 =1\n",
    "        if time[0]=='?' and time[1]=='?':\n",
    "            res1 = 24\n",
    "        elif time[0]=='?':\n",
    "            if int(time[1])<=3:\n",
    "                res1 = 3\n",
    "            else:\n",
    "                res1 =2\n",
    "        elif time[1]=='?':\n",
    "            if int(time[0])<=1:\n",
    "                res1 = 10\n",
    "            else:\n",
    "                res1 = 4\n",
    "        else:\n",
    "            res1 =1\n",
    "        return res1*res2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def count(time: str, limit: int) -> int:\n",
    "    ans = 0\n",
    "    for i in range(limit):\n",
    "        s = f\"{i:02}\"\n",
    "        if all(t =='?' or t == c for t, c in zip(time, s)):\n",
    "            ans += 1\n",
    "    return ans\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        return count(time[:2], 24) * count(time[3:], 60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        count_1,count_2=0,0\n",
    "        if time[0]=='?' and time[1]=='?':\n",
    "            count_1=24\n",
    "        elif time[0]=='?' and int(time[1])<=3:\n",
    "            count_1=3\n",
    "        elif time[0]=='?' and int(time[1])>3:\n",
    "            count_1=2\n",
    "        elif time[0]=='2' and time[1]=='?':\n",
    "            count_1=4\n",
    "        elif time[0]!='2' and time[1]=='?':\n",
    "            count_1=10\n",
    "        else:\n",
    "            count_1=1\n",
    "        if time[3]=='?' and time[4]=='?':\n",
    "            count_2=60\n",
    "        elif time[3]=='?' and time[4]!='?':\n",
    "            count_2=6\n",
    "        elif time[3]!='?' and time[4]=='?':\n",
    "            count_2=10\n",
    "        else:\n",
    "            count_2=1\n",
    "        return count_1*count_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        def check(s: str, t: str) -> bool:\n",
    "            return all(a == b or b == '?' for a, b in zip(s, t))\n",
    "\n",
    "        return sum(check(f'{h:02d}:{m:02d}', time) for h in range(24) for m in range(60))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "\n",
    "        if time[:2] == '??':\n",
    "            ans = 24\n",
    "        elif time[0] == '?':\n",
    "            ans = 2 + (time[1] < '4')\n",
    "        elif time[1] == '?':\n",
    "            ans = 4 if time[0] == '2' else 10\n",
    "        \n",
    "        if time[3] == '?':\n",
    "            ans *= 6\n",
    "        if time[4] == '?':\n",
    "            ans *= 10\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        result=1\n",
    "        if time[0]=='?':\n",
    "            if time[1]=='?':\n",
    "                result*=24\n",
    "            elif time[1]<='3':\n",
    "                result*=3\n",
    "            else:\n",
    "                result*=2\n",
    "        elif time[0]<'2':\n",
    "            if time[1]=='?':\n",
    "                result*=10\n",
    "        else:\n",
    "            if time[1]=='?':\n",
    "                result*=4\n",
    "        if time[3]=='?':\n",
    "            if time[4]=='?':\n",
    "                result*=60\n",
    "            else:\n",
    "                result*=6\n",
    "        else:\n",
    "            if time[4]=='?':\n",
    "                result*=10\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hours = 1\n",
    "        minutes = 1\n",
    "\n",
    "        if time[0]=='?':\n",
    "            if time[1]=='?':\n",
    "                hours =  24\n",
    "            elif int(time[1])>=4:\n",
    "                hours =  2\n",
    "            else:\n",
    "                hours =  3\n",
    "        elif time[1]==\"?\":\n",
    "            if int(time[0])==2:\n",
    "                hours = 4\n",
    "            else:\n",
    "                hours = 10\n",
    "        else:\n",
    "            hours=1\n",
    "\n",
    "        \n",
    "\n",
    "        if time[3]=='?':\n",
    "            minutes*=6\n",
    "        if time[4]=='?':\n",
    "            minutes*=10\n",
    "        # print(hours,minutes)\n",
    "        return hours*minutes\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        n = len(time)\n",
    "\n",
    "        def dfs(i):\n",
    "            nonlocal ans\n",
    "            if i == n:\n",
    "                hh = int(pre[0]+pre[1])\n",
    "                mm = int(pre[-2]+pre[-1])\n",
    "                ans += 0<=hh<24 and 0<=mm<60\n",
    "                return \n",
    "            if time[i] != \"?\":\n",
    "                pre.append(time[i])\n",
    "                dfs(i+1)\n",
    "                pre.pop()\n",
    "            else:\n",
    "                for x in range(10):\n",
    "                    pre.append(str(x))\n",
    "                    dfs(i+1)\n",
    "                    pre.pop()\n",
    "            return \n",
    "        \n",
    "        ans = 0        \n",
    "        pre = []\n",
    "        dfs(0)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def count(t: str, period: int) -> int:\n",
    "    ans = 0\n",
    "    for i in range(period):\n",
    "        if (t[0] == '?' or i // 10 == int(t[0])) and \\\n",
    "           (t[1] == '?' or i % 10 == int(t[1])):\n",
    "            ans += 1\n",
    "    return ans\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        return count(time[:2], 24) * count(time[3:], 60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hours = 1\n",
    "        if time[0] == \"?\":\n",
    "            if time[1] == \"?\":\n",
    "                hours = 24\n",
    "            else:\n",
    "                hours = 2 if int(time[1]) > 3 else 3\n",
    "        if time[1] == \"?\":\n",
    "            if time[0] == \"?\":\n",
    "                hours = 24\n",
    "            else:\n",
    "                hours = 10 if int(time[0]) < 2 else 4\n",
    "        c = 6 if time[3] == \"?\" else 1\n",
    "        d = 10 if time[4] == \"?\" else 1\n",
    "        return hours * c * d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        cnt = 0\n",
    "        for h1 in range(0, 3):\n",
    "            if time[0] != '?' and int(time[0]) != h1:\n",
    "                continue\n",
    "            for h2 in range(0 if h1 < 2 else 0, 10):\n",
    "                if time[1] != '?' and int(time[1]) != h2:\n",
    "                    continue\n",
    "                hour = h1 * 10 + h2\n",
    "                if hour >= 24:\n",
    "                    continue\n",
    "                for m1 in range(0, 6):\n",
    "                    if time[3] != '?' and int(time[3]) != m1:\n",
    "                        continue\n",
    "                    for m2 in range(0, 10):\n",
    "                        if time[4] != '?' and int(time[4]) != m2:\n",
    "                            continue\n",
    "                        minute = m1 * 10 + m2\n",
    "                        if minute >= 60:\n",
    "                            continue\n",
    "                        cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        n = 0\n",
    "        m = 0\n",
    "        if time[0] == \"?\" and time[1] != \"?\":\n",
    "            if int(time[1]) < 4:\n",
    "                n = 3\n",
    "            else:\n",
    "                n = 2\n",
    "        elif time[0] != \"?\" and time[1] == \"?\":\n",
    "            if int(time[0]) == 2:\n",
    "                n = 4\n",
    "            else:\n",
    "                n = 10\n",
    "        elif time[0] == \"?\" and time[1] == \"?\":\n",
    "            n = 24\n",
    "        else:\n",
    "            n = 0\n",
    "        \n",
    "        if time[3] == \"?\" and time[4] != \"?\":\n",
    "            m = 6\n",
    "        elif time[3] != \"?\" and time[4] == \"?\":\n",
    "            m = 10\n",
    "        elif time[3] == \"?\" and time[4] == \"?\":\n",
    "            m = 60\n",
    "        else:\n",
    "            m = 0\n",
    "        \n",
    "        if m == 0 and n == 0:\n",
    "            return 1\n",
    "        elif m != 0 and n == 0:\n",
    "            return m\n",
    "        elif m == 0 and n != 0:\n",
    "            return n\n",
    "        else:\n",
    "            return m*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h = m = 1\n",
    "        if time[0] == time[1] == '?':\n",
    "            h = 24\n",
    "        elif time[0] == '?':\n",
    "            h = 2 + (time[1] < '4')\n",
    "        elif time[1] == '?':\n",
    "            h = 4 if time[0] == '2' else 10\n",
    "        \n",
    "        if time[3] == time[4] == '?':\n",
    "            m = 60\n",
    "        elif time[3] == '?':\n",
    "            m = 6\n",
    "        elif time[4] == '?':\n",
    "            m = 10\n",
    "\n",
    "        return h * m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        t = time.split(\":\")\n",
    "        ans = 1\n",
    "        h = t[0]\n",
    "        m = t[1]\n",
    "        if h[0] == \"?\" and h[1] == \"?\":\n",
    "            ans *= 24\n",
    "        elif h[0] == \"?\":\n",
    "            if int(h[1]) <= 3:\n",
    "                ans *= 3\n",
    "            else:\n",
    "                ans *= 2\n",
    "        elif h[1] == \"?\":\n",
    "            if int(h[0]) <= 1:\n",
    "                ans *= 10\n",
    "            else:\n",
    "                ans *= 4\n",
    "        \n",
    "        if m[0] == \"?\" and m[1] == \"?\":\n",
    "            ans *= 60\n",
    "        elif m[0] == \"?\":\n",
    "            ans *= 6\n",
    "        elif m[1] == \"?\":\n",
    "            ans *= 10\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        return self.count(time[:2], 24) * self.count(time[3:], 60)\n",
    "\n",
    "    def count(self, t:str, period:int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(period):\n",
    "            if (t[0] == '?' or i // 10 == int(t[0])) and \\\n",
    "            (t[1] == '?' or i % 10 == int(t[1])):\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute\n",
    "\n",
    "\n",
    "\n",
    "            \n",
    "\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        if \"?\" not in time:\n",
    "            return 1\n",
    "        t = time.split(\":\")\n",
    "        hm = 1\n",
    "        if t[0] == \"??\":\n",
    "            hm = 24\n",
    "        elif t[0][0] == \"?\":\n",
    "            hm = 2\n",
    "            if int(t[0][1]) < 4:\n",
    "                hm =  3\n",
    "        elif t[0][1] == \"?\":\n",
    "            hm = 10\n",
    "            if int(t[0][0]) ==2:\n",
    "                hm = 4\n",
    "        \n",
    "        sm = 1\n",
    "        if t[1] == \"??\":\n",
    "            sm = 60\n",
    "        elif t[1][0] == \"?\":\n",
    "            sm = 6\n",
    "        elif t[1][1] == \"?\":\n",
    "            sm  = 10\n",
    "        \n",
    "        return sm * hm\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        n1,n2 = 0,0\n",
    "        if time[0] == '?' and time[1] == \"?\":\n",
    "            n1 = 2 * 10 + 1 * 4\n",
    "        elif time[0] != '?' and time[1] != \"?\":\n",
    "            n1 = 1\n",
    "        else:\n",
    "            if time[0] != '?':\n",
    "                n1 = 4 if time[0] == '2' else 10\n",
    "            else:\n",
    "                n1 = 3 if time[1] < '4' else 2\n",
    "        \n",
    "        if time[3] == \"?\" and time[4] == \"?\":\n",
    "            n2 = 6 * 10\n",
    "        elif time[3] != '?' and time[4] != \"?\":\n",
    "            n2 = 1\n",
    "        else:\n",
    "            if time[3] != '?':\n",
    "                n2 = 10\n",
    "            elif time[4] != '?':\n",
    "                n2 = 6\n",
    "        return n1 * n2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def countTime(self, time: str) -> int:\n",
    "#         a,b=1,1\n",
    "#         if time[1]==\"?\":\n",
    "#             if time[0]==\"?\":\n",
    "#                 a=24\n",
    "#             else:\n",
    "#                 if time[0]<'2':\n",
    "#                     a=10\n",
    "#                 else:\n",
    "#                     a=4\n",
    "#         else:\n",
    "#             if time[0]==\"?\":\n",
    "#                 if time[1]<'4':\n",
    "#                     a=3\n",
    "#                 else:\n",
    "#                     a=2\n",
    "\n",
    "#         if time[3]==\"?\":\n",
    "#             b*=6\n",
    "#         if time[4]==\"?\":\n",
    "#             b*=10\n",
    "\n",
    "#         return a*b\n",
    "\n",
    "\n",
    "### 灵茶山\n",
    "def count(t: str, period: int) -> int:\n",
    "\n",
    "    ans = 0\n",
    "\n",
    "    for i in range(period):\n",
    "\n",
    "        if (t[0] == '?' or i // 10 == int(t[0])) and \\\n",
    "           (t[1] == '?' or i % 10 == int(t[1])):\n",
    "\n",
    "            ans += 1\n",
    "\n",
    "    return ans\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def countTime(self, time: str) -> int:\n",
    "\n",
    "        return count(time[:2], 24) * count(time[3:], 60)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        H=[i for i in range(24)]\n",
    "        M=[i for i in range(60)]\n",
    "        self.sums=0\n",
    "        def dd(Str):\n",
    "            Set=Str.find('?')\n",
    "            if Set==-1:\n",
    "                if int(Str[0:2]) in H and int(Str[3:]) in M:\n",
    "                    self.sums+=1\n",
    "            else:\n",
    "                for i in range(10):\n",
    "                    dd(Str.replace('?',str(i),1))\n",
    "        dd(time)\n",
    "        return self.sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        count_h=1\n",
    "        count_m=1\n",
    "        if time[0]==\"?\":\n",
    "            if time[1] == \"?\":\n",
    "                count_h+=23\n",
    "            elif int(time[1]) < 4:\n",
    "                count_h+=2\n",
    "            elif int(time[1]) > 3:\n",
    "                count_h+=1\n",
    "        elif time[0]!=\"?\" and time[1]==\"?\":\n",
    "            if int(time[0])<2:\n",
    "                count_h+=9\n",
    "            elif int(time[0])==2:\n",
    "                count_h+=3\n",
    "        elif time[0] != \"?\" and time[1] != \"?\":\n",
    "            count_h=1\n",
    "        if time[3]==\"?\":\n",
    "            if time[4]==\"?\":\n",
    "                count_m+=59\n",
    "            elif int(time[4])>0:\n",
    "                count_m+=5\n",
    "            elif int(time[4])==0:\n",
    "                count_m+=5\n",
    "        elif time[3] !=\"?\" and time[4]==\"?\":\n",
    "            if int(time[3])<6:\n",
    "                count_m+=9\n",
    "        elif time[3] != \"?\" and time[4] != \"?\":\n",
    "            count_m=1\n",
    "        return count_h*count_m\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        count_Hour = 0\n",
    "        count_Minute = 0\n",
    "\n",
    "        for i in range(24):\n",
    "            a = i // 10\n",
    "            b = i % 10\n",
    "            if (time[0] == '?' or int(time[0]) == a) and (time[1] == '?' or int(time[1])  == b):\n",
    "                count_Hour += 1\n",
    "        for j in range(60):\n",
    "            a = j // 10\n",
    "            b = j % 10\n",
    "            if (time[3] == '?' or int(time[3]) == a) and (time[4] == '?' or int(time[4]) == b):\n",
    "                count_Minute += 1\n",
    "        return count_Hour * count_Minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        # if '?' not in time:\n",
    "        #     return 0\n",
    "        n1,n2 = 0,0\n",
    "        if time[0] == '?' and time[1] == \"?\":\n",
    "            n1 = 2 * 10 + 1 * 4\n",
    "        elif time[0] != '?' and time[1] != \"?\":\n",
    "            n1 = 1\n",
    "        else:\n",
    "            if time[0] != '?':\n",
    "                n1 = 4 if time[0] == '2' else 10\n",
    "            else:\n",
    "                n1 = 3 if time[1] < '4' else 2\n",
    "        \n",
    "        if time[3] == \"?\" and time[4] == \"?\":\n",
    "            n2 = 6 * 10\n",
    "        elif time[3] != '?' and time[4] != \"?\":\n",
    "            n2 = 1\n",
    "        else:\n",
    "            if time[3] != '?':\n",
    "                n2 = 10\n",
    "            elif time[4] != '?':\n",
    "                n2 = 6\n",
    "        return n1 * n2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "        if time[0]=='?':\n",
    "            if time[1]=='?':\n",
    "                ans*=24\n",
    "            elif int(time[1])>3:\n",
    "                ans*=2\n",
    "            elif int(time[1])<=3:\n",
    "                ans*=3\n",
    "        elif time[0]=='2':\n",
    "            if time[1]=='?':\n",
    "                ans*=4\n",
    "        else:\n",
    "            if time[1]=='?':\n",
    "                ans*=10\n",
    "        if time[3]=='?':\n",
    "            ans*=6\n",
    "        if time[4]=='?':\n",
    "            ans*=10\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        def countt(t:str, period: int)-> int:\n",
    "            ans= 0\n",
    "            for i in range(period):\n",
    "                if (t[0]== '?' or i//10 == int(t[0])) and \\\n",
    "                    (t[1]== '?' or i%10 == int(t[1])):\n",
    "                    ans += 1\n",
    "            return ans\n",
    "\n",
    "        #return countt(time([:2]), 24)*countt(time[3:], 60)\n",
    "        return countt(time[:2], 24) * countt(time[3:], 60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        return self.count(time[: 2], 24) * self.count(time[-2:], 60)\n",
    "        \n",
    "\n",
    "    def count(self, chars: str, number: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(number):\n",
    "            if (chars[0] == '?' or chars[0] == str(i // 10)) and \\\n",
    "            (chars[1] == '?' or chars[1] == str(i % 10)):\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        if time[0]=='?' and time[1]=='?':\n",
    "            a=24\n",
    "        elif time[0]=='?':\n",
    "            if int(time[1])>3:\n",
    "                a=2\n",
    "            else:\n",
    "                a=3\n",
    "        elif time[1]=='?':\n",
    "            if int(time[0])==2:\n",
    "                a=4\n",
    "            else:\n",
    "                a=10\n",
    "        else:\n",
    "            a=1  \n",
    "        if time[3]=='?':\n",
    "            b=6\n",
    "        else:\n",
    "            b=1\n",
    "        if time[4]=='?':\n",
    "            c=10\n",
    "        else:\n",
    "            c=1\n",
    "        return a*b*c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "        if time[0] == \"?\":\n",
    "            if time[1] == \"?\":\n",
    "                ans *= 24\n",
    "            elif int(time[1]) < 4:\n",
    "                ans *= 3\n",
    "            else:\n",
    "                ans *= 2\n",
    "        else:\n",
    "            if time[1] == \"?\":\n",
    "                if time[0] == \"1\" or time[0] == \"0\":\n",
    "                    ans *= 10\n",
    "                if time[0] == \"2\":\n",
    "                    ans *= 4\n",
    "        if time[3] == \"?\":\n",
    "            if time[4] == \"?\":\n",
    "                ans *= 60\n",
    "            else:\n",
    "                ans *= 6\n",
    "        else:\n",
    "            if time[4] == \"?\":\n",
    "                ans *= 10\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "        if time[0] == '?' and time[1] == '?': ans *= 24\n",
    "        elif time[0] == '?': ans *= 2 if time[1] > '3' else 3\n",
    "        elif time[1] == '?': ans *= 4 if time[0] == '2' else 10\n",
    "        if time[3] == '?': ans *= 6\n",
    "        if time[4] == '?': ans *= 10\n",
    "        return ans\n",
    "                 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        def count(time,up):\n",
    "            ans = 0\n",
    "            for h in range(up):\n",
    "                s = f\"{h:02}\"\n",
    "                for t,c in zip(time,s):\n",
    "                    if t!=\"?\" and t!=c:\n",
    "                        break\n",
    "                else:\n",
    "                    ans +=1\n",
    "            return ans\n",
    "        return count(time[:2],24) * count(time[3:],60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def count(t: str, period: int) -> int:\n",
    "    ans = 0\n",
    "    for i in range(period):\n",
    "        if  (t[0] == \"?\" or i // 10 == int(t[0])) and \\\n",
    "            (t[1] == \"?\" or i % 10 == int(t[1])):\n",
    "            ans += 1\n",
    "    return ans\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        return count(time[:2], 24 ) * count(time[3:], 60)\n",
    "        \n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        if time[0]==\"?\" and time[1]==\"?\" and time[3]==\"?\" and time[4]==\"?\" :\n",
    "            return 1440\n",
    "        if time[0]==\"?\" and time[1]==\"?\" and time[3]==\"?\" and time[4]!=\"?\":\n",
    "            return 24*6\n",
    "        if time[0]==\"?\" and time[1]==\"?\" and time[3]!=\"?\" and time[4]!=\"?\" :\n",
    "            return 24\n",
    "        if time[0]==\"?\" and time[1]!=\"?\" and time[3]!=\"?\" and time[4]!=\"?\" :\n",
    "            return 2 if int(time[1])>3 else 3\n",
    "        if time[0]!=\"?\" and time[1]==\"?\" and time[3]==\"?\" and time[4]==\"?\" :\n",
    "            return 600 if int(time[0])<2 else 240\n",
    "        if time[0]!=\"?\" and time[1]!=\"?\" and time[3]==\"?\" and time[4]==\"?\" :\n",
    "            return 60\n",
    "        if time[0]!=\"?\" and time[1]!=\"?\" and time[3]!=\"?\" and time[4]==\"?\" :\n",
    "            return 10\n",
    "        if time[0]==\"?\" and time[1]!=\"?\" and time[3]==\"?\" and time[4]!=\"?\" :\n",
    "            return 12 if int(time[1])>3 else 18\n",
    "        if time[0]==\"?\" and time[1]!=\"?\" and time[3]!=\"?\" and time[4]==\"?\" :\n",
    "            return 20 if int(time[1])>3 else 30\n",
    "        if time[0]!=\"?\" and time[1]==\"?\" and time[3]==\"?\" and time[4]!=\"?\" :\n",
    "            return 24 if int(time[0])==2 else 60\n",
    "        if time[0]!=\"?\" and time[1]==\"?\" and time[3]!=\"?\" and time[4]==\"?\" :\n",
    "            return 40 if int(time[0])==2 else 100\n",
    "        if time[0]==\"?\" and time[1]!=\"?\" and time[3]==\"?\" and time[4]==\"?\" :\n",
    "            return 120 if int(time[1])>3 else  180\n",
    "        if time[0]!=\"?\" and time[1]==\"?\" and time[3]!=\"?\" and time[4]!=\"?\" :\n",
    "            return 10 if int(time[0])<2 else 4\n",
    "        if time[0]!=\"?\" and time[1]!=\"?\" and time[3]==\"?\" and time[4]!=\"?\" :\n",
    "            return 6\n",
    "        if time[0]==\"?\" and time[1]==\"?\" and time[3]!=\"?\" and time[4]==\"?\" :\n",
    "            return 240\n",
    "        if time[0]!=\"?\" and time[1]!=\"?\" and time[3]!=\"?\" and time[4]!=\"?\" :\n",
    "            return 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        po = 1\n",
    "        bo = 1\n",
    "        if time[0] == '?':\n",
    "            if time[1] == '?':\n",
    "                po = 24\n",
    "            elif time[1] > '3':\n",
    "                po = 2\n",
    "            else:\n",
    "                po = 3\n",
    "        elif time[0] == '2':\n",
    "                if time[1] == '?':\n",
    "                    po = 4\n",
    "                else:\n",
    "                    po = 1\n",
    "        else:\n",
    "                if time[1] == '?':\n",
    "                    po = 10\n",
    "                else:\n",
    "                    po = 1\n",
    "\n",
    "        if time[3] == '?':\n",
    "            if time[4] == '?':\n",
    "                bo = 60\n",
    "            else:\n",
    "                bo = 6\n",
    "        else:\n",
    "            if time[4] == '?':\n",
    "                bo = 10\n",
    "            else:\n",
    "                bo = 1\n",
    "\n",
    "        return bo * po"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, times: str) -> int:\n",
    "        ans1 = 0\n",
    "        if times[0] == \"?\" and times[1] == \"?\":\n",
    "            ans1 += 24\n",
    "        if times[0] == \"?\" and times[1] != \"?\":\n",
    "            if times[1] < \"4\":\n",
    "                ans1 += 3\n",
    "            else:\n",
    "                # print(\"ss\")\n",
    "                ans1 += 2\n",
    "        if times[1] == \"?\" and times[0] != \"?\":\n",
    "            if times[0] < \"2\":\n",
    "                ans1 += 10\n",
    "            else:\n",
    "                ans1 += 4\n",
    "        if times[0] != \"?\" and times[1] != \"?\":\n",
    "            ans1 += 1\n",
    "\n",
    "        ans2 = 0\n",
    "        if times[3] == \"?\" and times[4] == \"?\":\n",
    "            ans2 += 60\n",
    "        elif times[3] == \"?\" and times[4] != \"?\": \n",
    "            ans2 += 6\n",
    "        elif times[4] == \"?\" and times[3] != \"?\":\n",
    "            ans2 += 10\n",
    "        elif times[3] != \"?\" and times[4] != \"?\":\n",
    "            ans2 += 1\n",
    "        return ans1 * ans2\n",
    "            \n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        cnth, cntm = 0, 0\n",
    "        for i in range(24):\n",
    "            if time[0] in ('?', str(i // 10)) and time[1] in ('?', str(i % 10)): cnth += 1\n",
    "        for i in range(60):\n",
    "            if time[3] in ('?', str(i // 10)) and time[4] in ('?', str(i % 10)): cntm += 1\n",
    "        return cnth * cntm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        # ans = 1\n",
    "        # if time[0] == \"?\":\n",
    "        #     if time[1] == \"?\":\n",
    "        #         ans *= 24\n",
    "        #     else:\n",
    "        #         ans *= (2 if time[1] >= \"4\" else 3)\n",
    "        # elif time[0] != \"?\" and time[1] == \"?\":\n",
    "        #     ans *= (4 if time[0] >= \"2\" else 10)\n",
    "        \n",
    "        # if time[3] == \"?\":\n",
    "        #     if time[4] == \"?\":\n",
    "        #         ans *= 60\n",
    "        #     else:\n",
    "        #         ans *= 6\n",
    "        # elif time[3] != \"?\" and time[4] == \"?\":\n",
    "        #     ans *= 10\n",
    "        # return ans\n",
    "\n",
    "\n",
    "        ans = 1\n",
    "        if time[0] == \"?\" and time[1] == \"?\":\n",
    "            ans *= 24\n",
    "        elif time[0] == \"?\" and time[1] != \"?\":\n",
    "            ans *= (2 if time[1] >= \"4\" else 3)\n",
    "        elif time[0] != \"?\" and time[1] == \"?\":\n",
    "            ans *= (4 if time[0] >= \"2\" else 10)\n",
    "\n",
    "        if time[3] == \"?\" and time[4] == \"?\":\n",
    "            ans *= 60\n",
    "        elif time[3] == \"?\" and time[4] != \"?\":\n",
    "            ans *= 6\n",
    "        elif time[3] != \"?\" and time[4] == \"?\":\n",
    "            ans *= 10\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "        a,b = time[:2]\n",
    "        c,d = time[3:]\n",
    "#分\n",
    "        if c == '?' and d == '?':\n",
    "            ans *= 60\n",
    "        elif c == '?':\n",
    "            ans *= 6\n",
    "        elif d == '?':\n",
    "            ans *= 10\n",
    "\n",
    "#时\n",
    "        if a == '?' and b == '?':\n",
    "            ans *= 24\n",
    "        elif a == '?':\n",
    "            if int(b) < 4:\n",
    "                ans *= 3\n",
    "            else:\n",
    "                ans *= 2\n",
    "        elif b == '?':\n",
    "            if int(a) == 2:\n",
    "                ans *= 4\n",
    "            else:\n",
    "                ans *= 10\n",
    "        return ans\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 0\n",
    "        for i in range(1440):\n",
    "            hour = i // 60\n",
    "            minute = i % 60\n",
    "            if time[0] == \"?\" or hour // 10 == int(time[0]) - 0:\n",
    "                if time[1] == \"?\" or hour % 10 == int(time[1]) - 0:\n",
    "                    if time[3] == \"?\" or minute // 10 == int(time[3]) - 0:\n",
    "                        if time[4] == \"?\" or minute % 10 == int(time[4]) - 0:\n",
    "                            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hour, minute = 1, 1\n",
    "        if time[0]==time[1]=='?':\n",
    "            hour=24\n",
    "        elif time[0]=='?':\n",
    "            if time[1]<'4':\n",
    "                hour=3\n",
    "            else:\n",
    "                hour=2\n",
    "        elif time[1]=='?':\n",
    "            if time[0]=='2':\n",
    "                hour=4\n",
    "            else:\n",
    "                hour=10\n",
    "        \n",
    "        if time[-2]==time[-1]=='?':\n",
    "            minute=60\n",
    "        elif time[-2]=='?':\n",
    "            minute=6\n",
    "        elif time[-1]=='?':\n",
    "            minute=10\n",
    "        \n",
    "        return hour*minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 0\n",
    "        for t in (\"%02d:%02d\" % (h, m) for h in range(24) for m in range(60)):\n",
    "            ok = True\n",
    "            for i in range(5):\n",
    "                if time[i] != '?' and time[i] != t[i]:\n",
    "                    ok = False\n",
    "                    break\n",
    "            ans += ok\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        count_h = 1\n",
    "        count_m = 1\n",
    "        if time[0] == '?':\n",
    "            if time[1] == '?':\n",
    "                count_h = 24\n",
    "            elif int(time[1]) >= 4:\n",
    "                count_h *= 2\n",
    "            elif int(time[1]) <= 3:\n",
    "                count_h *= 3\n",
    "\n",
    "        if time[1] == '?':\n",
    "            if time[0] == '?':\n",
    "                count_h = 24\n",
    "            elif int(time[0]) <= 1:\n",
    "                count_h *= 10\n",
    "            elif int(time[0]) == 2:\n",
    "                count_h *= 4\n",
    "\n",
    "        if time[3] == '?':\n",
    "            if time[4].isdigit():\n",
    "                count_m *= 6\n",
    "            else:\n",
    "                count_m = 60\n",
    "        \n",
    "        if time[4] == '?':\n",
    "            if time[3].isdigit():\n",
    "                count_m *= 10\n",
    "            else:\n",
    "                count_m = 60\n",
    "        \n",
    "        return count_h * count_m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hour,min=time.split(':')\n",
    "        a=b=0\n",
    "        if hour[0]==hour[1]=='?':\n",
    "            a=24\n",
    "        elif hour[0]=='?' and hour[1]!='?':\n",
    "            if int(hour[1])<4:\n",
    "                a=3\n",
    "            else:\n",
    "                a=2\n",
    "        elif hour[1]=='?' and hour[0]!='?':\n",
    "            if hour[0]!='2':\n",
    "                a=10\n",
    "            else:\n",
    "                a=4\n",
    "        else:\n",
    "            a=1\n",
    "        \n",
    "        if min[0]==min[1]=='?':\n",
    "            b=60\n",
    "        elif min[0]=='?' and min[1]!='?':\n",
    "            b=6\n",
    "        elif min[1]=='?' and min[0]!='?':\n",
    "            b=10\n",
    "        else:\n",
    "            b=1\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        def help_tool(t:str, size:int)->int:\n",
    "            temp = 0\n",
    "            for i in range(size):\n",
    "                if (t[0]=='?' or i//10==int(t[0])) and (t[1]=='?' or i%10==int(t[1])):\n",
    "                    temp +=1\n",
    "            return temp\n",
    "        return (help_tool(time[:2],24)*help_tool(time[-2:],60))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        nums = time.split(\":\")\n",
    "        hour = 0\n",
    "        minute = 0\n",
    "\n",
    "        if nums[0][0] == \"?\":\n",
    "            if nums[0][1] == \"?\":\n",
    "                hour = 24\n",
    "            else:\n",
    "                if int(nums[0][1]) <= 3:\n",
    "                    hour = 3\n",
    "                else:\n",
    "                    hour = 2\n",
    "        else:\n",
    "            if nums[0][1] == \"?\":\n",
    "                if int(nums[0][0]) < 2:\n",
    "                    hour = 10\n",
    "                else:\n",
    "                    hour = 4\n",
    "            else:\n",
    "                hour = 1\n",
    "        \n",
    "        if nums[1][0] == \"?\":\n",
    "            if nums[1][1] == \"?\":\n",
    "                minute = 60\n",
    "            else:\n",
    "                minute = 6\n",
    "        else:\n",
    "            if nums[1][1] == \"?\":\n",
    "                minute = 10\n",
    "            else:\n",
    "                minute = 1\n",
    "        return hour * minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        k1=time[0:2]\n",
    "        k2=time[-2::]\n",
    "        r1,r2=1,1\n",
    "        k11=[]\n",
    "        k22=[]\n",
    "        for i in k1:\n",
    "            if i ==\"?\":\n",
    "                k11.append(1)\n",
    "            else:\n",
    "                k11.append(0)\n",
    "\n",
    "        for i in k2:\n",
    "            if i ==\"?\":\n",
    "                k22.append(1)\n",
    "            else:\n",
    "                k22.append(0)\n",
    "\n",
    "        if k11==[1,1]:\n",
    "            r1=24\n",
    "        elif k11==[1,0]:\n",
    "            if int(k1[1])>=4:\n",
    "                r1=2\n",
    "            else:\n",
    "                r1=3\n",
    "        elif k11==[0,1]:\n",
    "            if int(k1[0])<=1:\n",
    "                r1=10\n",
    "            else:\n",
    "                r1=4\n",
    "        else:\n",
    "            r1=1\n",
    "\n",
    "        if k22==[1,1]:\n",
    "            r2=60\n",
    "        elif k22==[1,0]:\n",
    "            r2=6\n",
    "        elif k22==[0,1]:\n",
    "            r2=10\n",
    "        else:\n",
    "            r2=1\n",
    "        return r1*r2\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        countHour = 0\n",
    "        countMinute = 0\n",
    "        for i in range(24):\n",
    "            hiHour = i // 10\n",
    "            loHour = i % 10\n",
    "            if ((time[0] == '?' or int(time[0]) == hiHour) and\n",
    "                    (time[1] == '?' or int(time[1]) == loHour)):\n",
    "                countHour += 1\n",
    "\n",
    "        for i in range(60):\n",
    "            hiMinute = i // 10\n",
    "            loMinute = i % 10\n",
    "            if ((time[3] == '?' or int(time[3]) == hiMinute) and\n",
    "                    (time[4] == '?' or int(time[4]) == loMinute)):\n",
    "                countMinute += 1\n",
    "\n",
    "        return countHour * countMinute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        \"\"\"\n",
    "        :type time: str\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        global tim\n",
    "        global remain\n",
    "        global coun\n",
    "        tim=time[0:2]+time[3:5]\n",
    "        p=[3,10,6,10]\n",
    "        coun=0\n",
    "        remain=''\n",
    "        def check(x):\n",
    "            global coun\n",
    "            if len(x)==4 and int(x[0:2])<=23 and int(x[2:4])<60:\n",
    "                coun+=1\n",
    "        def t(x):\n",
    "            global tim\n",
    "            global remain\n",
    "            if x==4:\n",
    "                check(remain)\n",
    "            elif tim[x]=='?' and ('?' not in tim[x+1:]):\n",
    "                for i in range(p[x]):\n",
    "                    check(remain+str(i)+tim[x+1:])\n",
    "            elif tim[x]=='?':\n",
    "                for i in range(p[x]):\n",
    "                    remain=remain[:x]+str(i)\n",
    "                    t(x+1)\n",
    "            else:\n",
    "                remain+=tim[x]\n",
    "                t(x+1)\n",
    "        t(0)        \n",
    "        return coun"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        lst = []\n",
    "        for i in range(24):\n",
    "            for j in range(60):\n",
    "                lst.append('%02d:%02d' % (i, j))\n",
    "        ans = 0\n",
    "        for s in lst:\n",
    "            for i in range(5):\n",
    "                if time[i] != '?' and time[i] != s[i]:\n",
    "                    break\n",
    "            else:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "\n",
    "        flag=1\n",
    "\n",
    "        for i in time:\n",
    "            if i=='?':\n",
    "                flag=0\n",
    "                break\n",
    "        if flag:\n",
    "            return 1\n",
    "\n",
    "        time=time.split(':')\n",
    "\n",
    "        h=time[0]\n",
    "        m=time[1]\n",
    "\n",
    "        a=0\n",
    "        b=0\n",
    "\n",
    "        for i in range(len(h)):\n",
    "            if h[0]=='?':\n",
    "                if h[1]=='?':\n",
    "                    a=24\n",
    "                elif int(h[1])>3:\n",
    "                    a=2\n",
    "                else:\n",
    "                    a=3\n",
    "            else:\n",
    "                if h[1]=='?':\n",
    "                    if int(h[0])==2:\n",
    "                        a=4\n",
    "                    elif 0<=int(h[0])<2:\n",
    "                        a=10\n",
    "                    else:\n",
    "                        return 0\n",
    "                else:\n",
    "                    a=1\n",
    "\n",
    "        \n",
    "        for i in range(len(m)):\n",
    "            if m[0]=='?':\n",
    "                if m[1]=='?':\n",
    "                    b=60\n",
    "                else:\n",
    "                    b=6\n",
    "            else:\n",
    "                if m[1]=='?':\n",
    "                    b=10\n",
    "                else:\n",
    "                    b=1\n",
    "        print(a,b)\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "# 暴力枚举\n",
    "class Solution:\n",
    "    def countTime(self, t: str) -> int:\n",
    "        ans = 0\n",
    "        for h in range(24):\n",
    "            for m in range(60):\n",
    "                s = f\"{h:02}:{m:02}\"\n",
    "                suc = True\n",
    "                for c1, c2 in zip(t, s):\n",
    "                    if c1 == '?' or c1 == c2:\n",
    "                        continue\n",
    "                    suc = False\n",
    "                    break\n",
    "                if suc:\n",
    "                    ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h = m = 1\n",
    "\n",
    "        if time[:2] == '??':\n",
    "            h = 24\n",
    "        elif time[0] == '?':\n",
    "            h = 2 + (time[1] < '4')\n",
    "        elif time[1] == '?':\n",
    "            h = 4 if time[0] == '2' else 10\n",
    "        \n",
    "        if time[3] == '?':\n",
    "            m *= 6\n",
    "        if time[4] == '?':\n",
    "            m *= 10\n",
    "\n",
    "        return h * m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        lst=[1,1,1,1]\n",
    "        if time[0]=='?':\n",
    "            if time[1]=='?':\n",
    "                lst[1]=24\n",
    "            elif 0<=int(time[1])<=3:\n",
    "                lst[0]=3\n",
    "            elif 3<int(time[1])<=9:\n",
    "                lst[0]=2\n",
    "        if time[1]=='?'and time[0]!='?':\n",
    "            if time[0]!='2':\n",
    "                lst[1]=10\n",
    "            else:\n",
    "                lst[1]=4\n",
    "        if time[3]=='?':\n",
    "            lst[2]=6\n",
    "        if time[4]=='?':\n",
    "            print('----------')\n",
    "            lst[3]=10\n",
    "        print(lst[0],lst[1],lst[2],lst[3])\n",
    "        return lst[0]*lst[1]*lst[2]*lst[3]\n",
    "a=Solution()\n",
    "print(a.countTime(\"??:??\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans=1\n",
    "        a,b,c,d=time[0],time[1],time[3],time[4]\n",
    "        if a==\"?\":\n",
    "            if b==\"?\": ans*=24\n",
    "            elif b>=\"4\": ans*=2\n",
    "            else: ans*=3\n",
    "        if b==\"?\":\n",
    "            if a==\"2\": ans*=4\n",
    "            elif a==\"0\" or a==\"1\": ans*=10\n",
    "        if c==\"?\":\n",
    "            ans*=6\n",
    "        if d==\"?\":\n",
    "            ans*=10\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h = 1\n",
    "        if time[:2] == \"??\":\n",
    "            h = 24\n",
    "        else:\n",
    "            if time[0] == \"?\":\n",
    "                h = 2 if int(time[1]) > 3 else 3\n",
    "            if time[1] == \"?\":\n",
    "                h = 10 if int(time[0]) < 2 else 4\n",
    "        a = 6 if time[3] == \"?\" else 1\n",
    "        b = 10 if time[4] == \"?\" else 1\n",
    "        return h * a * b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans=1\n",
    "        x=time[0:2].count('?')\n",
    "        if x==0:\n",
    "            ans*=1\n",
    "        if x==2:\n",
    "            ans *=24\n",
    "        if x==1:\n",
    "            if time[0]=='?':\n",
    "                if int(time[1])<=3:\n",
    "                    ans *=3\n",
    "                else:ans*=2\n",
    "            if time[1]=='?':\n",
    "                if int(time[0])==2:\n",
    "                    ans *= 4\n",
    "                else: ans*=10\n",
    "        y=time[3:5].count('?')\n",
    "        if y==0:\n",
    "            ans*= 1\n",
    "        if y==2:\n",
    "            ans*= 60\n",
    "        if y==1:\n",
    "            if time[3]=='?':\n",
    "                ans*=6\n",
    "            else:ans*=10\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        def check(time: str) -> bool:\n",
    "            hh, mm = time[:2], time[3:]\n",
    "            return 0 <= int(hh) <= 23 and 0 <= int(mm) <= 59\n",
    "        cnt = 1\n",
    "        if time[:2].count(\"?\") == 2:\n",
    "            cnt *= 24\n",
    "        elif time[:2].count(\"?\") == 1:\n",
    "            if time[0] == \"?\":\n",
    "                if 0 <= int(time[1]) <= 3:\n",
    "                    cnt *= 3\n",
    "                else:\n",
    "                    cnt *= 2\n",
    "            else:\n",
    "                if int(time[0]) != 2:\n",
    "                    cnt *= 10\n",
    "                else:\n",
    "                    cnt *= 4\n",
    "        if time[3:].count(\"?\") == 2:\n",
    "            cnt *= 60\n",
    "        elif time[3:].count(\"?\") == 1:\n",
    "            if time[3] == \"?\":\n",
    "                cnt *= 6\n",
    "            else:\n",
    "                cnt *= 10\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h, m = time[:2], time[-2:]\n",
    "        h_cnt, m_cnt = 1, 1\n",
    "        if h[0] == \"?\":\n",
    "            if h[1] == \"?\":\n",
    "                h_cnt = 24\n",
    "            else:\n",
    "                h_cnt = 3 if h[1] < \"4\" else 2\n",
    "        elif h[1] == \"?\":\n",
    "            h_cnt = 10 if h[0] < \"2\" else 4\n",
    "        if m[0] == \"?\":\n",
    "            m_cnt = 60 if m[1] == \"?\" else 6\n",
    "        elif m[1] == \"?\":\n",
    "            m_cnt = 10\n",
    "        return h_cnt * m_cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        res = 1\n",
    "        if time[0] == '?':\n",
    "            if time[1] != '?':\n",
    "                if int(time[1]) <= 3:\n",
    "                    res *= 3\n",
    "                else:\n",
    "                    res *= 2\n",
    "            else:\n",
    "                res *= 24\n",
    "        \n",
    "        if time[1] == '?' and time[0] != '?':\n",
    "            if int(time[0]) == 2:\n",
    "                res *= 4\n",
    "            else:\n",
    "                res *= 10\n",
    "        \n",
    "        if time[3] == '?':\n",
    "            res *= 6\n",
    "        if time[4] == '?':\n",
    "            res *= 10\n",
    "        \n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        h = m = 1\n",
    "        if time[0] == time[1] == '?':\n",
    "            h = 24\n",
    "        elif time[0] == '?':\n",
    "            h = 2 + (time[1] < '4')\n",
    "        elif time[1] == '?':\n",
    "            h = 4 if time[0] == '2' else 10\n",
    "        \n",
    "        if time[3] == '?':\n",
    "            m *= 6\n",
    "        if time[4] == '?':\n",
    "            m *= 10\n",
    "\n",
    "        return h * m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ids = []\n",
    "        for idx, value in enumerate(time):\n",
    "            if value == \"?\":\n",
    "                ids.append(idx)\n",
    "        ans = 1\n",
    "\n",
    "        if 0 in ids and 1 in ids:\n",
    "            ans = ans*24\n",
    "        elif 0 in ids and 1 not in ids and int(time[1]) >= 4:\n",
    "            ans = ans*2\n",
    "        elif 0 in ids and 1 not in ids and int(time[1]) < 4:\n",
    "            ans = ans*3\n",
    "        elif 0 not in ids and 1 in ids and int(time[0]) < 2:\n",
    "            ans = ans*10\n",
    "        elif 0 not in ids and 1 in ids and int(time[0]) == 2:\n",
    "            ans = ans*4\n",
    "\n",
    "        if 3 in ids:\n",
    "            ans = ans*6\n",
    "        \n",
    "        if 4 in ids:\n",
    "            ans = ans*10\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        ans = 1\n",
    "        tmp1 = time[3]\n",
    "        tmp2 = time[4]\n",
    "        if tmp1 == '?':\n",
    "            ans *= 6\n",
    "        if tmp2 == '?':\n",
    "            ans *= 10\n",
    "\n",
    "        tmp1 = time[0]\n",
    "        tmp2 = time[1]\n",
    "        if tmp1 == '?':\n",
    "            if tmp2 == '?':\n",
    "                ans *= 24\n",
    "            else:\n",
    "                if int(tmp2) >= 4:\n",
    "                    ans *= 2\n",
    "                else:\n",
    "                    ans *= 3\n",
    "        else:\n",
    "            if tmp2 == '?':\n",
    "                if int(tmp1) < 2:\n",
    "                    ans *= 10\n",
    "                else:\n",
    "                    ans *= 4\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def countTime(self, time: str) -> int:\n",
    "#         hour_type = 1\n",
    "#         minute_type = 1\n",
    "#         hour, minute = time.split(':')\n",
    "#         if hour == \"??\":\n",
    "#             hour_type = 24\n",
    "#         elif hour.count('?') == 1:\n",
    "#             if hour[0] == '?':\n",
    "#                 if int(hour[1]) < 4:\n",
    "#                     hour_type = 3\n",
    "#                 else:\n",
    "#                     hour_type = 2\n",
    "#             elif hour[1] == '?':\n",
    "#                 if int(hour[0]) < 2:\n",
    "#                     hour_type = 10\n",
    "#                 elif int(hour[0]) == 2:\n",
    "#                     hour_type = 4\n",
    "#         if minute == '??':\n",
    "#             minute_type = 60\n",
    "#         elif minute.count('?') == 1:\n",
    "#             if minute[0] == '?':\n",
    "\n",
    "#                 minute_type = 6\n",
    "#             else:\n",
    "#                 minute_type = 10\n",
    "#         return hour_type*minute_type\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hour_type = 1\n",
    "        minute_type = 1\n",
    "        hour, minute = time.split(':')\n",
    "        if hour == \"??\":\n",
    "            hour_type = 24\n",
    "        elif hour.count('?') == 1:\n",
    "            if hour[1] == \"?\":\n",
    "                if int(hour[0]) == 2:\n",
    "                    hour_type = 4\n",
    "                elif int(hour[0]) < 2:\n",
    "                    hour_type = 10\n",
    "            elif hour[0] == \"?\":\n",
    "                if int(hour[1]) < 4:\n",
    "                    hour_type = 3\n",
    "                else:\n",
    "                    hour_type = 2\n",
    "        if minute == \"??\":\n",
    "            minute_type = 60\n",
    "        elif minute.count(\"?\") == 1:\n",
    "            if minute[0] == \"?\":\n",
    "                minute_type = 6\n",
    "            elif minute[1]==\"?\":\n",
    "                minute_type=10\n",
    "        return hour_type*minute_type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        H=[i for i in range(24)]\n",
    "        M=[i for i in range(60)]\n",
    "        self.sums=0\n",
    "        def dd(Str):\n",
    "            Set=Str.find('?')\n",
    "            if Set==-1:\n",
    "                if int(Str[0:2]) in H and int(Str[3:]) in M:\n",
    "                    self.sums+=1\n",
    "            else:\n",
    "                for i in range(10):\n",
    "                    dd(Str.replace('?',str(i),1))\n",
    "        dd(time)\n",
    "        return self.sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        H=[i for i in range(24)]\n",
    "        M=[i for i in range(60)]\n",
    "        self.sums=0\n",
    "        def dd(Str):\n",
    "            Set=Str.find('?')\n",
    "            if Set==-1:\n",
    "                if int(Str[0:2]) in H and int(Str[3:]) in M:\n",
    "                    self.sums+=1\n",
    "            else:\n",
    "                for i in range(10):\n",
    "                    dd(Str.replace('?',str(i),1))\n",
    "        dd(time)\n",
    "        return self.sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def count(self,time:str,limit:int):\n",
    "        ans = 0\n",
    "        for i in range(limit):\n",
    "            s = f'{i:02}'\n",
    "            if all(t == '?' or t == c for t, c in zip(time, s)):\n",
    "                ans += 1\n",
    "        return ans\n",
    "\n",
    "    def countTime(self, time: str) -> int:\n",
    "        # ans = 0\n",
    "        # for h in range(24):\n",
    "        #     for m in range(60):\n",
    "        #         s = f'{h:02}:{m:02}'\n",
    "        #         ok = True\n",
    "        #         for t, i in zip(time, s):\n",
    "        #             if t != '?' and t != i:\n",
    "        #                 ok = False\n",
    "        #                 break\n",
    "        #         if ok:\n",
    "        #             ans += 1\n",
    "        # return ans\n",
    "        return self.count(time[:2],24) * self.count(time[3:],60)\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countTime(self, time: str) -> int:\n",
    "        hour_type = 1\n",
    "        minute_type = 1\n",
    "        hour, minute = time.split(':')\n",
    "        if hour == \"??\":\n",
    "            hour_type = 24\n",
    "        elif hour.count('?') == 1:\n",
    "            if hour[0] == '?':\n",
    "                if int(hour[1]) < 4:\n",
    "                    hour_type = 3\n",
    "                else:\n",
    "                    hour_type = 2\n",
    "            elif hour[1] == '?':\n",
    "                if int(hour[0]) < 2:\n",
    "                    hour_type = 10\n",
    "                elif int(hour[0]) == 2:\n",
    "                    hour_type = 4\n",
    "        if minute == '??':\n",
    "            minute_type = 60\n",
    "        elif minute.count('?') == 1:\n",
    "            if minute[0] == '?':\n",
    "\n",
    "                minute_type = 6\n",
    "            else:\n",
    "                minute_type = 10\n",
    "        return hour_type*minute_type\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 暴力枚举\n",
    "class Solution:\n",
    "    def countTime(self, t: str) -> int:\n",
    "        ans = 0\n",
    "        for h in range(24):\n",
    "            for m in range(60):\n",
    "                s = f\"{h:02}:{m:02}\"\n",
    "                suc = True\n",
    "                for c1, c2 in zip(t, s):\n",
    "                    if c1 != '?' and c1 != c2:\n",
    "                        suc = False\n",
    "                        break\n",
    "                if suc:\n",
    "                    ans += 1\n",
    "        return ans\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
